package logic

import (
	"context"
	"fmt"
	"time"
	"user-sys/models"
	"user-sys/pkg"

	"user-sys/user_rpc/internal/svc"
	"user-sys/user_rpc/user_rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ImageCaptchaLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewImageCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageCaptchaLogic {
	return &ImageCaptchaLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ImageCaptchaLogic) ImageCaptcha(in *user_rpc.ImageCaptchaRequest) (*user_rpc.ImageCaptchaResponse, error) {
	// todo: add your logic here and delete this line
	key := fmt.Sprintf("account form InageCaptcha:%s", in.Account)
	code, image := pkg.ImageCaptcha()
	models.RDB.Set(models.Ctx, key, code, 5*time.Minute)
	return &user_rpc.ImageCaptchaResponse{
		Image: image,
	}, nil
}
